package com.doit.demo05;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class test {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        new Thread(new FutureTask<Integer>(new Callable<Integer>() {
//            @Override
//            public Integer call() throws Exception {
//                int sum = 0;
//                for (int i = 0; i <=100; i++) {
//                    sum+=i;
//                }
//                System.out.println(sum);
//                return 0;
//            }
//        })).start();
//        new Thread(new FutureTask<Integer>(new Callable<Integer>() {
//            @Override
//            public Integer call() throws Exception {
//                int sum = 0;
//                for (int i = 0; i <=200; i++) {
//                    sum+=i;
//                }
//                System.out.println(sum);
//                return 0;
//            }
//        })).start();
        My_Call mc = new My_Call(100);
        FutureTask<Integer> ft = new FutureTask<>(mc);
        Thread t = new Thread(ft);
        t.start();
        System.out.println(ft.get());

        My_Call mcc = new My_Call(200);
        FutureTask<Integer> ftt = new FutureTask<>(mcc);
        Thread tt = new Thread(ftt);
        tt.start();
        System.out.println(ftt.get());

    }
}
